package hw.txtreader.fragment;

import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.LinearSnapHelper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;
import java.util.List;

import hw.txtreader.R;
import hw.txtreader.adapter.PoliceImgAdapter;
import hw.txtreader.base.BaseFragment;
import hw.txtreader.databinding.FragmentFirstBinding;
import hw.txtreader.listener.OnItemClickListener;

public class FirstFragment extends BaseFragment {


    FragmentFirstBinding binding;
    PoliceImgAdapter adapter;
    List<Integer> listRes = new ArrayList<>();
    LinearSnapHelper mLinearSnapHelper;


    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        binding = DataBindingUtil.inflate(LayoutInflater.from(getActivity()), R.layout.fragment_first,null,false);
        binding.setFragment(this);

        initView();
        return binding.getRoot();
    }

    private void initView() {
        LinearLayoutManager manager = new LinearLayoutManager(getActivity());
        manager.setOrientation(LinearLayoutManager.HORIZONTAL);
        binding.rlModule.setLayoutManager(manager);
        mLinearSnapHelper = new LinearSnapHelper();
        mLinearSnapHelper.attachToRecyclerView(binding.rlModule);
        binding.rlModule.setItemAnimator(new DefaultItemAnimator());
        if (!listRes.contains(R.mipmap.icon_doctor_first)) {
            listRes.add(R.mipmap.icon_doctor_first);
        }

        if (!listRes.contains(R.mipmap.icon_doctor_second)) {
            listRes.add(R.mipmap.icon_doctor_second);
        }

        if (!listRes.contains(R.mipmap.icon_doctor_third)) {
            listRes.add(R.mipmap.icon_doctor_third);
        }

        if (!listRes.contains(R.mipmap.icon_doctor_forth)) {
            listRes.add(R.mipmap.icon_doctor_forth);
        }

        if (!listRes.contains(R.mipmap.icon_doctor_fifth)) {
            listRes.add(R.mipmap.icon_doctor_fifth);
        }

        if (!listRes.contains(R.mipmap.icon_doctor_sixth)) {
            listRes.add(R.mipmap.icon_doctor_sixth);
        }

        if (!listRes.contains(R.mipmap.icon_doctor_seventh)) {
            listRes.add(R.mipmap.icon_doctor_seventh);
        }

        adapter = new PoliceImgAdapter(getActivity(),listRes);
        binding.rlModule.setAdapter(adapter);
        adapter.setOnItemClickLitener(new OnItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {

            }

            @Override
            public void onItemLongClick(View view, int position) {

            }
        });

    }
}
